package com.luo.backend.schedule;

import com.luo.backend.service.EmailVerificationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 邮箱验证码定时任务
 */
@Component
public class EmailVerificationScheduler {
    
    private static final Logger logger = LoggerFactory.getLogger(EmailVerificationScheduler.class);
    
    @Autowired
    private EmailVerificationService emailVerificationService;
    
    /**
     * 每天凌晨2点清理过期验证码
     * cron表达式: 秒 分 时 日 月 周
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void cleanExpiredVerificationCodes() {
        logger.info("开始执行定时任务：清理过期验证码");
        try {
            emailVerificationService.cleanExpiredCodes();
            logger.info("定时任务执行成功：清理过期验证码完成");
        } catch (Exception e) {
            logger.error("定时任务执行失败：清理过期验证码出错", e);
        }
    }
}



